/*
 * @Author: Liz.Zheng
 * @Date: 2021-09-29 17:45:02
 * @LastEditTime: 2022-10-10 13:41:56
 * @LastEditors: 郑亚莉 zhengyali@shequ.life
 * @Description: 根据项目按需全局引入的ant design等组件；全局挂载事件等；
 * @Motto: Write the code. Change the world.
 */

import {
  ConfigProvider,
  Button,
  Input,
  Layout,
  Modal,
  Tooltip,
  Popover,
  Select,
  Menu,
  Card,
  Form,
  InputNumber,
  Radio,
  Checkbox,
  Upload,
  Table,
  Drawer,
  Switch,
  Tree,
  Row,
  Col,
  Badge,
  PageHeader,
  Dropdown,
  Avatar,
  Tag,
  List,
  Descriptions,
  DatePicker,
  Divider,
  Spin,
  Cascader,
  Popconfirm,
  Collapse,
  Tabs,
  Space,
  Alert,
  Empty,
  TimePicker,
  Timeline,
  TimelineItem,
  Pagination,
  Progress,
  Image,
  Mentions,
} from "ant-design-vue";
import i18n from "../../locale";
import store from "../../store";
import {router} from "../../router/index";
import utils from "./utils";
import CuIcon from "./icon";
import defaultSetting from "./defaultSetting";

const appUse = (app) => {
  // 路由导航
  app.use(router);
  // 全局多语言
  app.use(i18n);
  // vuex
  app.use(store);
  // 使用自定义图标库
  app.component("CuIcon", CuIcon);
  // 全局引入部分常用antd 组件
  app.use(ConfigProvider);
  app.use(Button);
  app.use(Input);
  app.use(Layout);
  app.use(Tooltip);
  app.use(Popover);
  app.use(Select);
  app.use(Menu);
  app.use(Modal);
  app.use(Card);
  app.use(Form);
  app.use(InputNumber);
  app.use(Radio);
  app.use(Checkbox);
  app.use(Upload);
  app.use(Table);
  app.use(Drawer);
  app.use(Switch);
  app.use(Tree);
  app.use(Row);
  app.use(Col);
  app.use(Badge);
  app.use(PageHeader);
  app.use(Dropdown);
  app.use(Avatar);
  app.use(Tag);
  app.use(List);
  app.use(Descriptions);
  app.use(DatePicker);
  app.use(Divider);
  app.use(Spin);
  app.use(Cascader);
  app.use(Popconfirm);
  app.use(Collapse);
  app.use(Tabs);
  app.use(Space);
  app.use(Alert);
  app.use(Empty);
  app.use(TimePicker);
  app.use(Timeline);
  app.use(TimelineItem);
  app.use(Pagination);
  app.use(Progress);
  app.use(Image);
  app.use(Mentions);
  app.config.globalProperties.$utils = utils;
  app.config.globalProperties.$settings = defaultSetting;
  // 按钮权限控制
  // 1 显隐控制
  app.directive("permission", {
    beforeMount(el, binding) {
      if (!utils.actionPermission(binding.value)) {
        el.style.display = "none";
      }
    },
  });
  // 2是否可点击控制
  app.directive("action", {
    mounted(el, binding) {
      if (!utils.actionPermission(binding.value)) {
        el.disabled = true;
        el.title = "您没有权限操作";
      }
    },
  });
};

export default appUse;
